home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Education
/
World of Education.iso
/
world_s
/
startrek.zip
/
CHAPTER.005
next >
Wrap
Text File
|
1989-05-15
|
43KB
|
991 lines
Chapter 5 page 1 STARTREK THE COMPUTER PROGRAM By Joe Kasser
CHAPTER 5
5.1 Using the Sub-systems
Before any of the sub-systems can be used they must be in
working order. Thus the state of each on-board sub-systems has
to be stored and tested before any sub-system is used. This
task is performed by the Damage Control subroutine.
5.2 Damage control
The damage control section is an important part of the
Starship. It keeps track of the state of repair of all the
subsystems and allows the player to activate that system only if
it is working order. Thus for example, the player cannot use
Phasers to shoot at the enemy if the Phaser Banks have been
damaged.
The state of the subsystems are stored in an array labeled
D(I) such that
D(0) = the state of the Engines (Navigation)
D(1) = the state of the Short Range Sensors
D(2) = the state of the Long Range Sensors
D(3) = the state of the Phasers
D(4) = the state of the Photon Torpedoes
D(5) = the state of the Computer
D(6) = the state of the Shields
etc.
Gaining access to the state of any sub-system is then a
matter of accessing the appropriate element in the array. For
example, if the state of the Phaser Banks is required, looking at
the contents of the fourth element of the array counting from 0
or D(3) will tell us how they are.
A damage control status display shows the state of any
damaged sub-system by displaying its name and the estimated time
for repairs to be completed (ETR) as shown in the following
typical display.
DAMAGE CONTROL AT QUADRANT 4,6
SYSTEM ETR
LONG RANGE SENSORS 1
PHASERS 2
HOW MANY DAYS TO SPEND ON REPAIRS SIR ?
The state of the Long Range Sensors and the Phaser banks are
shown together with their estimated time to complete repairs
(ETR). The player is also asked to allocate time to perform the
repairs. If the player chooses not to wait for the repairs to be
performed, but move around and take the chance of fighting only
armed with torpedoes, zero time can be entered as a response to
the question.
Copyright (c) Joe Kasser 1989
Chapter 5 page 2 STARTREK THE COMPUTER PROGRAM By Joe Kasser
If the ETR is stored in the elements of the array directly,
then examining the contents of any element will tell us how long
it will take for the sub-system to be repaired. For example, if
the value stored in D(4) is 2 then the ETR for the Phaser Banks
is between 1 and 2 stardates.
If the value stored in the element is 0 then that sub-system
is in working order. Conversely any sub-system containing a
value greater than 0 in the D(I) array, is damaged. Using this
principle we can display the state of the sub-systems, fix any of
them by setting the contents of the element to 0 or damage
something by setting the contents of the particular element to a
positive value.
The flow chart for the damage control subroutine is shown in
figure 5.1. The procedure begins by displaying the heading. A
loop is then performed to identify if any sub-system is damaged
(ie, check if the value stored in the D(I) matrix is greater than
zero. If none of the sub-systems are damaged, a message is
displayed accordingly. If at least one is damaged, the estimated
time to repair stored in the array associated with the damaged
sub-system is displayed. Repairs are in order only if the
condition is not Red, namely, there are no Klingons in the
Quadrant. If this condition is true, the repair time allocation
is requested and the repairs carried out. If anything is fixed,
that happening is displayed. Finally the time remaining in the
game is adjusted to cover the time that has passed performing the
repairs.
The technique used to display the state of the contents of
the D(I) array is to sample the contents of each element of the
array in turn and test to see if it equal to 0. If it is greater
than 0, damage is present. The BASIC statement to test
something is the IF statement. The state of the contents of each
element in turn can be tested by a set of statements such as
IF D(I) = 0 THEN
A set of such statements where I = 0, in the first one, I = 1 in
the second one can be used as follows
2801 IF D(0) = 0 THEN 2821
2811 REM LINE SOMEHOW DISPLAYS THE DAMAGE MESSAGE
2821 IF D(1) = 0 THEN 2841
2831 REM LINE SOMEHOW DISPLAYS THE DAMAGE MESSAGE
2841 IF D(2) = 0 THEN 2861
2851 REM LINE SOMEHOW DISPLAYS THE DAMAGE MESSAGE
and so on for all the elements in the array. This is a
perfectly valid section of a program but there is a better way.
We know that there are up to C1 elements in the array (0, 1, 2,
3, 4, 5, and so on). Change the routine to read
2801 LET I = 0
2811 IF D(I) = 0 THEN 2831
2821 REM SOMEHOW DISPLAY THE DAMAGE MESSAGE IN THIS LINE
Copyright (c) Joe Kasser 1989
Chapter 5 page 3 STARTREK THE COMPUTER PROGRAM By Joe Kasser
2831 LET I = I + 1
2841 IF I < C1 THEN 2811
2851 REM PROGRAM FLOW CONTINUES HERE AFTER THE LOOP
While this technique works, it puts the onus on the
programmer to increment the loop counter (I) for each pass
through the loop. BASIC contains a built in loop counter that
takes care of the loop counter. Using the 'FOR/NEXT' pair of
statements, the loop can be constructed as follows
2801 FOR I = 0 TO C1 : REM TEST C1 ELEMENTS
2811 IF D(I) = 0 THEN 2831
2821 REM SOMEHOW DISPLAY THE DAMAGE MESSAGE IN THIS LINE
2831 NEXT
2841 REM PROGRAM FLOW CONTINUES HERE AFTER THE LOOP
The 'FOR/NEXT' construction thus may be used to simplifY the
construction of loops.
BASIC also builds into the 'FOR/NEXT' loop the capability to
advance the loop counter by more than one step per pass using the
'STEP' statement.
2801 FOR I = 0 TO C1 STEP 2
will for example loop using values of I equal to 0, 2, 4 and 6
sequentially, and will skip values of I equal to 1, 3 and 5
So far the discussions have not considered how the state of
the sub-system is displayed. The technique used here is to
store the names of each sub-system in a String Array, D$(I) in
the same order as the D(I) array that contains the state of the
system.
Lines 4570/4590 set up the names of each of the C1-C2
subsystems that can be damaged in an array containing C1 elements
labeled D$(I) which happens to be a part of the array used to
store the C1 command function names, such that
D$(0) = "WARP ENGINES"
D$(1) = "SHORT RANGE SENSORS"
D$(2) = "LONG RANGE SENSORS"
D$(3) = "PHASER BANKS"
D$(4) = "PHOTON TORPEDO TUBES"
D$(5) = "MAP (COMPUTER)"
D$(6) = "SHIELDS"
ETC.
Now the BASIC statement to display something at the terminal
is PRINT. Thus PRINT D$(I) would print the name stored in the
D$(I) array for the corresponding value of I. For example if you
wanted all the names to be listed, you could type the following
routine into the existing game program in the computer.
Copyright (c) Joe Kasser 1989
Chapter 5 page 4 STARTREK THE COMPUTER PROGRAM By Joe Kasser
2811 REM DEMO LOOP
2821 FOR I = 0 TO C1
2831 PRINT D$(I)
2841 NEXT
2851 RETURN
If you now type in the word RUN you tell the computer to
execute your program. When you get the 'COMMAND ?' prompt, enter
the word 'DAM' to initiate the Damage Control command. The
resultant listing would be as follows
WARP ENGINES
SHORT RANGE SENSORS
LONG RANGE SENSORS
PHASERS
PHOTON TORPEDOES
COMPUTER
SHIELDS
LONG RANGE PROBES
TRANSPORTER
SHUTTLECRAFT
DAMAGE CONTROL
VISUAL
RESIGN
SAVE THE STATE OF THE GAME
LOAD A SAVED GAME
COMMAND ?
At this time hold down the 'CNTRL' (Control) key with one
finger and touch the 'C' key with the other. You have just
interrupted the program in mid-flow by typing in the Control-C
character also written as ^C. The computer should give you
message saying that a BREAK occurred.
In our instance we want to print out the name of the sub-
system and its estimated repair time, namely two things. BASIC
allows that by the use of the comma (,) or semi-colon (;)
separators. For example the statements
2831 PRINT D$(I),D(I)
and
2831 PRINT D$(I);D(I)
do not perform the same operation.
The semi-colon displays the second (or subsequent) item to
be displayed immediately following the previous one, while the
comma performs a tab function which moves the printhead or cursor
over to the next tab position just as an electric typewriter.
So from before, the FOR/NEXT routine to display the names of
the sub-systems and their repair times would thus require
changing line 2831 to
Copyright (c) Joe Kasser 1989
Chapter 5 page 5 STARTREK THE COMPUTER PROGRAM By Joe Kasser
2831 PRINT D$(I),D(I)
Again type RUN (carriage return). When you get the 'COMMAND
?' prompt, try the 'DAM' command. The resultant listing will not
be perfectly formatted. Try it and see. The reason that the
display is not formatted properly is because the lengths of the
names of the sub-systems are different. The built in tab feature
in BASIC will only tab across to the next tab position.
You can set your own tab position anywhere along the line by
using the TAB statement. If line 2831 is changed to
2831 PRINT D$(I) ; TAB(28) ; D(I)
the result will be formatted correctly. Break the program (^C),
change line 2831 and try it.
The flow chart for the DAMAGE.CONTROL function may be
implemented in BASIC as shown in figure 5.2.
Consider each of the lines in turn, what they do and how
they do it. The damage control function begins at line 2800 with
a REMark or comment statement telling you what function is being
performed.
It has already been mentioned that the most commonly used
subroutines are placed towards the beginning of the program.
This is done to speed up execution time, since most BASIC
interpreters search for line numbers sequentially from the top.
When you enter a line of code into a program in the interpretive
mode, the interpreter finds the position for the line and inserts
it in the correct place in the sequence of statements.
The Damage Control subroutine begins with the REMark
statement in line 2800. Line 2810 uses the subroutine at line 70
to display the name of the function being performed. A
temporary variable, D8 is then set to 0. A loop in lines 2820
and 2830 tests the status of each of the subsystems that can be
damaged in the damage control or commands array D(I). There are
C1 commands but only C1-C2 of them can be damaged. Damage
control cannot be damaged, that doesn't make sense. Visual
sensors similarly can't be damaged, and you can always try to
resign. The use of C1-C2 in line 2820 and later lines, allows
the routine to work if further commands are added. Adding a new
command later should only require changes in the command
subroutine, it should not require changes anywhere else in the
program. When you write programs keep them modular and make the
modules stand-alone. That means that changes in one function
should not require changes in more than one module. If you write
code that requires modifications to many of its modules when
implementing a change you will spend an awful lot of time
performing de-bugging, because you will have to do a lot of
searching to find where the modifications have to be made.
Copyright (c) Joe Kasser 1989
Chapter 5 page 6 STARTREK THE COMPUTER PROGRAM By Joe Kasser
If the value assigned to any sub-system in the array is
greater than zero, ie. signifying that something is damaged the
value of D8 is incremented by one. At this time, we are not
looking to see what is damaged, just if something is. A PRINT
statement is then executed to cause the display to advance one
line at the console and the value of D8 is tested. If it is
equal to zero then nothing is damaged and a message is displayed
accordingly. There is then no need to continue in the subroutine
and the GOTO 2910 statement causes the program to branch forward
to line 2910 skipping the remainder of the subroutine. The exact
value of D8 is not important at this time. It is however at this
time, a count of how many of the sub-systems are damaged.
The damage control display begins at line 2840. This line
displays the heading. The loop in lines 2850 and line 2860 now
examine the state of each item in the array. If any are damaged,
that fact is detected in line 2850 and a display of the name of
the sub-system and its estimated time to repair is made. The
estimate is printed out as an approximate number as follows.
The statement used is
PRINT INT(D(I)+Z).
This takes the value stored in the array, adds 1 to it and then
converts the result to an integer. this process is known as in
mathematics as "rounding up" to the next significant digit. The
process could have been written as
X = D(I) + Z : X = INT(X) : PRINT X
which would do the same job but require the use of an extra
(dummy) variable 'X'. The display is formatted by the TAB(28)
statement. After the state of all the systems have been
sampled, the presence of Klingons in the quadrant is then
determined. If the value of the variable K is greater than 0, at
least one Klingon is present in the quadrant (we don't care how
many at this time) and the subroutine ends at this time by GOing
TO line 2910.
At this stage we have reached line 2870. There are no
klingons in the quadrant so the value assigned to K is zero. A
'PRINT' statement is executed and the computer then requests the
number of stardates to be spent on repairs, using the 'INPUT'
statement and the prompt "HOW MANY DAYS TO SPEND ON REPAIRS SIR
". Note the space after the SIR. This space separates the SIR
from the ? that BASIC displays to inform the user that an input
is being requested. The player's reply is assigned to the
variable D8. D8 is thus re-used at this time.
Re-using variables is good practice because it saves memory,
but on the other hand, can lead to problems if the state of
variables are changed by different routines because it may be
difficult to find out where the change is being made. The
player's input is first checked to see if a negative number was
Copyright (c) Joe Kasser 1989
Chapter 5 page 7 STARTREK THE COMPUTER PROGRAM By Joe Kasser
input. If it was, the value of D8 is set to zero. After all we
cannot allow negative time in the game. The repairs are
performed in lines 2880 to 2900. For each sub-system liable to
damage a test is performed. If the sub-system is undamaged,
nothing happens to it and the program skips to line 2900. If
however it is damaged (the value assigned to D(I) > 0 ) then line
2890 is performed. The value assigned to D8 is subtracted from
the number stored in the array. If the result is equal to or
less than zero repairs have been completed and the sub-system
should be in working order. The value in the damage control
status array is then set to zero and a message that the sub-
system has been repaired is displayed at the console. When all
is said and done, line 2910 causes the subroutine to RETURN to
the main program loop.
The DAM subroutine uses one nested subroutine starting at
line 70 to format the headings on the various commanded displays.
Line 70 contains the comment while the operation is performed by
line 80. The name of the operation stored in the D$(I) array is
first displayed, followed by the words 'AT QUADRANT'. The
computer counts the quadrants from 0 to 7, but the player counts
them from 1 to 8. The adjustment is performed by the Q1+Z and
Q2+Z statements. Take careful note of the formatting semi colons
used in the line. When this subroutine is called, the value of I
has been set up in the command matching loop of lines 3060/3070
for the branch using the 'ON' statement in line 3080.
At first glance it seems that this procedure is too complex.
why not just subtract the D8 from D(I) for each element in the
array, and display a message for those having a result less than
zero. Well why not? the answer is a question. How do you then
detect the difference between systems in working order and those
that have just been repaired?
Delete lines 2811 to 2851 by typing 'DELETE 2811-2851' into
the computer. Notice the use of the 'DELETE' statement which can
be used to delete all or selected parts of a program. Here we
just deleted the temporary lines we used to play with the
formatting of the Damage Control Status display. The format of
the command is the same as that of the 'LIST' command. Some
dialects of BASIC may require a slightly different way of typing
the command (e.g. DELETE 2811,2851). Add lines 70, 80 and line
2800 to 2910 (as listed in figure 5.2) to the program and save
the program. Then RUN it. The damage control command should
work as should the "Help" command (Command 0). Interrupt the
program flow with a ^C and dummy in some damage. You do that as
follows. Let us enter some damage to the one sub-system by
typing in
D(3) = 4
which sets the damage status of device 3 to 4 stardates estimated
repair time. What we have done is interactively entered some
data directly into a variable from the console. It is a good way
to debug the program. Now to continue the program just type in
Copyright (c) Joe Kasser 1989
Chapter 5 page 8 STARTREK THE COMPUTER PROGRAM By Joe Kasser
CONT. Do not type RUN or the computer will reset all variables
to zero and you will lose your input for D(3). If you now
execute the Damage Control command you will get a notice that one
sub-system is damaged. Enter a repair time allocation of 2
stardates, and try the command again. See how the ETR has
changed. Now enter a repair time of 5 days and see if you get a
"REPAIRED" message. You should. You have now exercised the
damage control function and are ready to go onto bigger and
better things.
The next command to activate is the MAP (COMPUTER) command
so that we can take a look at how the galaxy was set up.
5.3 The Map Display
The map display is one of the Ship's computer functions. It
is directly accessible from the main command loop as well as from
the computer. It shows the contents of all the quadrants in the
galaxy that have been scanned by Long Range or Short Range
sensors or by Long Range Probes as a three digit number with the
following convention.
The 100's digit = number of Klingons
the 10's digit = number of Starbases
the 1's digit = number of Stars,
thus for example, 317 means that the quadrant contains 3
Klingons, 1 Starbase and 7 stars. Quadrants that are unscanned
show up as "***" on the display.
The flow chart to implement the MAP function is shown in
figure 5.3. The nested loops can be seen at a glance. The same
nesting technique is used as in the initialization routine. The
routine first tests to see if the map function is damaged. If it
is, a message is displayed stating that fact, if not, it is
assumed to be in working order and a map display is generated.
The map displays the contents of each of the quadrants and
emphasizes the quadrant containing the Enterprise. In this
version of the game, that emphasis is to display the quadrant
containing the Enterprise surrounded by '+' signs. A sample map
display is shown below.
Copyright (c) Joe Kasser 1989
Chapter 5 page 9 STARTREK THE COMPUTER PROGRAM By Joe Kasser
MAP FOR QUADRANT 4,6
1 2 3 4 5 6 7 8
1 *** *** *** *** *** *** *** ***
2 *** *** *** *** *** *** *** ***
3 *** *** *** *** *** *** *** ***
4 *** *** *** 001 012 104 *** ***
5 *** *** *** 002 +206+ 307 *** ***
6 *** *** *** 717 001 003 *** ***
7 *** *** *** *** *** *** *** ***
8 *** *** *** *** *** *** *** ***
The map display function can be written in BASIC as shown in
figure 5.4. The sequence begins at line 200 with the usual
REMark statement. Then line 210 tests the state of repair of the
MAP/COMPUTER. If it is in working order namely if D(I) = 0 then
the program flows on to line 220 skipping over the rest of line
210 which displays a message stating that the device is damaged
and causes the subroutine to exit via line 280. Line 210 could
alternatively be written using the IF/ELSE construct as
210 I=5 : IF D(I)=0 THEN 220 ELSE PRINT D$(I); "DOWN AT THIS TIME" : GOTO 280
this version of line 210 needs a dialect of BASIC that not only
recognizes the IF/ELSE construct, but also branches to the next
subsequent line number if the test fails. Which version is used
basically depends on the programmer. They all perform the same
operation. The implementation of the IF/ELSE-THEN statement in
BASIC may differ from version to version and tends to cause the
most problems when converting programs.
5.4 LONG RANGE SENSORS
Long Range sensors show the contents of the neighboring
quadrants but in minimal detail. An example of a long range
sensor scan is shown below;
LONG RANGE SENSORS FOR QUADRANT 4,6
001 012 104
002 206 317
717 001 003
The Enterprise is located in the quadrant shown in the center of
the display. The contents of each quadrant are described as a
three digit number with the following convention.
The 100's digit = number of Klingons
the 10's digit = number of Starbases
the 1's digit = number of Stars,
thus for example, 317 means that the quadrant contains 3
Klingons, 1 Starbase and 7 stars. Quadrants that are outside the
galaxy show up as "***" on the display.
Copyright (c) Joe Kasser 1989
Chapter 5 page 10 STARTREK THE COMPUTER PROGRAM By Joe Kasser
The display shows a small section of space around the
quadrant that the Enterprise is located in, in a similar format
to that of the Map display. This means that the display is
relative to the position of the Enterprise. The Enterprise is
always located in the center quadrant.
The flow chart for the procedure is shown in figure 5.5.
The routine begins with a test to see if the sensors are damaged.
If they are a message to that effect is displayed at the console
and the subroutine skips everything else. If they are not, the
standard sensor subsystem heading is displayed and the loops to
perform the actual display functions begun.
The loop counters each contain three iterations of their
respective loops. This sensor display shows the contents of
space with the co-ordinates of the Enterprise as the center. The
row display is thus with respect to Q1, the column display with
respect to Q2. The inside loop scans the quadrants in adjacent
columns to the Enterprise, the outside loop adjusts the row
counter so that the operation is performed on adjacent rows as
well. The quadrant containing the Enterprise is also scanned.
Thus for each quadrant in the loop, a test is first performed to
determine if the quadrant is inside the galaxy. If the quadrant
is inside the galaxy, and if the computer/map is not damaged, the
map array is updated. The contents of the quadrant are then
displayed at the console irrespective of the state of the
computer. As long as the Long Range Sensors are working, the
player will always get a scan display. The map however will only
be updated, if the ship's computer is also up.
If the quadrant being scanned is outside the galaxy, the
display will be "***". The cursor is moved over one character by
displaying a "space" character, and the loop continues with the
next quadrant in the row. When the row has been scanned by the
inner loop, the outer loop advances its loop counter to perform
the operation on the next row. Since the next row is to be
displayed on the next line the cursor is advanced to the start of
the next line before the next set of quadrants are displayed.
When the contents of all nine quadrants have been displayed, the
subroutine terminates.
The BASIC language implementation of the flow chart is shown
in figure 5.6.
The routine starts at line 300 with a REMark or comment.
Line 310 checks to see if the sensors are working (ie. if D(I) >
0 ). If they are working, the 'IF' test fails and the program
continues on line 320. If they are damaged, the program
continues along line 310, displaying a "DAMAGED" message and then
branching forward to the RETURN statement in line 370. You will
see many instances in many published programs where line 310 or
its equivalent will contain a 'RETURN' statement instead of the
'GOTO the line which terminates the subroutine'. Both execute
correctly, however it good practice to ensure that any
subroutine has only one exit point. It will make debugging a lot
Copyright (c) Joe Kasser 1989
Chapter 5 page 11 STARTREK THE COMPUTER PROGRAM By Joe Kasser
simpler.
Line 320 uses the subroutine beginning at line 70 to display
the heading for the sensor scan display, and then proceeds to set
up the loops for the row and column displays. The Long Range
Sensor display uses the same format as the Map display. The map
displayed the whole galaxy, but here in the Long Range Sensors we
only want to see what is in the adjacent quadrants. Namely we
want to look at quadrants on each side of the Enterprise's
location. Since the Enterprise is located at quadrant Q1,Q2 at
any time, our loop range must be the co-ordinates of the
Enterprise plus or minus one. Thus the program statement
FOR I = Q1 - Z TO Q1 + Z : FOR J = Q2 - Z TO Q2 + Z.
The PRINT " "; part of line 320 advances the cursor between
quadrant displays on the same line.
Line 330 tests to see if the quadrant being scanned is
outside the galaxy. Quadrants within the galaxy are numbered
from 0 to 7. Thus any quadrant with a row or a column number of
less than 0 ( <0 ) or greater than 7 ( >7 ) is out of the galaxy
by definition. The display for those quadrants is always a
"***". The program flow then jumps forward to NEXT statement in
line 360. If the quadrant being scanned is inside the galaxy,
line 340 tests the state of repair of the map/computer. If it is
up, the quadrant scanned is entered into the computer. The
quadrant is scanned using the ABS(X) function. This function
converts a number to its absolute or positive value. Thus a
positive value remains a positive value, while a negative value
is changed to a positive one. We thus don't care what the
previous state of the quadrant was before being scanned.
Lines 350, 360 and 370 perform the same functions as line
most of line 250, lines 260, 270 and 280 respectively. If you
want to save memory space you could delete lines 350 to 370 and
replace them by
350 GOTO 270
If you do this, you will also have to change the references to
those line numbers in lines 310 and 330. For example in line 330
you will have to change the 360 to 250. Since comprehension of
the program is easier if lines 350 to 370 are used, the program
has been written using them. Feel free to make the change if you
want to. You will also change the format of the display
slightly. Try it later on, and keep the version you like better
Carefully copy line 300 to 370 into your program. Debug
them as follows. First RUN the program. Perform the MAP
command. You should get the same unscanned display as before.
If the whole map shows up scanned, you forgot to delete line 211.
In that case, break the program and do it now. ReRUN the program.
Now do a Long Range Sensor command (LRS). You should then see
the normal long range sensor display. Then repeat the map
command, and the quadrants that were scanned by the long range
sensors should show up scanned on the map.
It is then time to break the program (^C). Damage the
Copyright (c) Joe Kasser 1989
Chapter 5 page 12 STARTREK THE COMPUTER PROGRAM By Joe Kasser
computer which will in effect damage the map by entering
D(5) = 3.
CONTinue the program and try the 'MAP' command. It won't work.
Try the 'LRS' or Long Range Sensor command. Now use the 'DAM' or
Damage Control command to fix the map and request another
display. The map should still be completely unscanned, because
the computer (map) itself was damaged at the time that the long
range scan was performed. Break the program again and damage the
long range sensors by entering
D(2) = 1.
CONTinue it and try the long range sensors again. They won't
work. Fix them and try the sensors followed by the map again.
The sensors should work, and the map display should also update.
If you like, break the program again and change the position of
the Enterprise by changing the values of Q1 and Q2. when you
continue the program, the long range scan will illuminate and
update a new section of the galaxy (if your new values for Q1 and
Q2 were within the range of 0 and 7 inclusive). If you made any
changes to the program during the debugging session,save the
program again at this point.
5.5 Long Range Probes
Long Range Probes are a means to find out what lies beyond
the range of the Long Range Sensors without moving. You can fire
a probe in any direction just as you would fire a photon torpedo.
The probe speeds away at about Warp Factor 10, as such it takes
about 0.1 stardates to cross a quadrant.
The probe sends back a status report in the same format as
the long range sensor/map data, as it enters each new quadrant.
The data received from the probe is automatically placed into the
computer, if the computer is up at the time that the data is
received. The communications technology used by the probes give
it a limited range however. The signal grows too weak to be
received when the probe is about five quadrants away from the
Enterprise.
If the probe enters a quadrant containing Klingons there is
a probability that they may detect and destroy it. Should you
try and launch one when in a battle situation, the simulator will
stop you.
4300 REM LONG RANGE PROBE (LRP.ASC)
4310 IF D(I)>0 THEN PRINT "LAUNCH CONTROL INOPERATIVE AT THIS TIME" : GOTO 4470
4320 L3=L3+Z : IF L3>7 THEN PRINT " No Probes left... Sir " : GOTO 4470
4330 IF K>0 THEN PRINT "You are not allowed to launch a probe during a battle" : GOTO 4470
4340 PRINT "LRP";L3;"Direction (1-9) "; : INPUT C : IF C=0 THEN 4470
4350 IF C<Z OR C>9 THEN 4340
4360 X1=Q1 : Y1=Q2 : X2=Q1+.5 : Y2=Q2+.5 : T1=T : FOR I=0 TO E0 : T=T-.1
4370 Y=(C-Z)*.785398 : X=COS(Y) : Y=-SIN(Y)
4380 X2=X2+Y : Y2=Y2+X : X1=INT(X2) : Y1=INT(Y2)
4390 IF SQR((X1-Q1)^2+(Y1-Q2)^2)>5 THEN PRINT "Probe out of range" : GOTO 4460
4400 PRINT X1+Z;",";Y1+Z;" =";
4410 IF X1<0 OR X1>7 OR Y1<0 OR Y1>7 THEN PRINT "***" : GOTO 4450
Copyright (c) Joe Kasser 1989
Chapter 5 page 13 STARTREK THE COMPUTER PROGRAM By Joe Kasser
4420 E$=STR$(Q(X1,Y1)) : E$="00"+MID$(E$,2) : PRINT RIGHT$(E$,3)
4430 IF D(5)=0 THEN Q(X1,Y1)=ABS(Q(X1,Y1))
4440 IF RND(Z)<ABS(Q(X1,Y1)+Z)/1000 THEN PRINT "Contact lost with probe" : GOTO 4460
4450 NEXT
4460 GOSUB 1800
4470 RETURN
1800 REM SUBROUTINE FOR REPAIRS AFTER TIME (T1-T)
1810 IF T<0 THEN F9=4 : GOTO 1870
1820 N=0 :FOR I=0 TO C1-C2 : IF D(I)=<0 THEN 1860
1830 D(I)=D(I)-(T1-T) : IF D(I)>0 THEN 1860
1840 IF N=0 THEN PRINT : PRINT "DAMAGE CONTROL REPORTING " : N=Z
1850 D(I)=0 : PRINT D$(I);"REPAIRED"
1860 NEXT
1870 RETURN
An alternative approach to implementing Long Range
Sensors is to send them on their way and allow time to pass while
they report back. If we assume that probes travel one quadrant
per stardate we can set up a scenario in which the program that
implements the function is split into two sections, namely one to
launch the probes, and the other that deals with the reporting.
This can be somewhat (but not absolutely true) considered as
foreground - background programming, in which the probes are
launched in foreground, where the action is, while the reporting
is done in background as time goes by.
The flowchart and code for the launching function would
be as shown below.
: PROBELAUNCH
PROBES.DAMAGED =?
YES (1) DISPLAY.MESSAGE
NO (1) PROBE.AVAILABLE =?
YES (2) REQUEST.AND.ACCEPT.COURSE
LAUNCH.PROBE
KLINGONS.IN.QUADRANT =?
YES (3) DO.THEY.DETECT.PROBE =?
YES (4) PROBE.DESTROYED
THEN (4)
THEN (3)
NO (2) DISPLAY."NONE.LEFT".MESSAGE
THEN (2)
THEN (1) ;
8005 REM LONG RANGE PROBE LAUNCH
8015 IF D(I)>0 THEN PRINT "LAUNCH CONTROL INOPERATIVE AT THIS TIME : GOTO 490
8025 FOR I = 0 TO 7 : IF L3(I)>0 THEN 8075
8035 INPUT "Course (1-8.99)";L4(I) : IF L4(I) = 0 THEN 8085
8045 IF L4(I)<Z OR L4(I)>8.99999 THEN 8035
8055 IF K>0 AND RND(Z)<K/7 THEN PRINT "Probe destroyed by the enemy" : L3(I) = 2 : GOTO 8085
8065 L1(I)=Q1 : L2(I)=Q2 : L6(I) = Q1+.5 : L7(I)=Q2+.5 : L3(I)=Z : L5(I)=T : PRINT "Probe";I+Z;"launched Sir" : GOTO 8085
8075 NEXT : PRINT " No Probes left... Sir "
8085 RETURN
8095 REM
Copyright (c) Joe Kasser 1989
Chapter 5 page 14 STARTREK THE COMPUTER PROGRAM By Joe Kasser
Copyright (c) Joe Kasser 1989
Chapter 5 page 15 STARTREK THE COMPUTER PROGRAM By Joe Kasser
The flowchart and code for the reporting function would
be as shown below.
: PROBE.REPORTING
LOOP (max.number.of.probes)
+ PROBE.ACTIVE =?
+ YES (1) DAY.PASSED.SINCE.LAST.REPORT =?
+ PROBE.IN.RANGE =?
8105 REM LONG RANGE PROBE REPORTING
8115 FOR I = 0 TO 7
8125 IF L3(I) <> Z OR (L5(I) - T) < Z THEN 8235
8135 Y = (L4(I)-Z)*.785398 : X = COS(Y) : Y = -SIN(Y)
8145 L6(I) = L6(I) + Y : L7(I) = L7(I) + X : L1(I) = INT(L6(I)) : L2(I) = INT(L7(I))
8155 IF SQR((L1(I)-Q1)^2+(L2(I)-Q2)^2)>5 THEN 8225
8165 IF L8 = Z THEN 8205
8175 PRINT "LRP";I+Z;"reporting from Quadrant";L1(I)+Z;",";L2(I)+Z;" =";
8185 IF L1(I)<0 OR L1(I)>7 OR L2(I)<0 OR L2(I)>7 THEN PRINT "***" : GOTO 8225
8195 E$ = STR$(Q(L1(I),L2(I))) : E$ = "00"+MID$(E$,2) : PRINT RIGHT$(E$,3)
8205 IF D(5) = 0 THEN Q(L1(I),L2(I)) = ABS(Q(L1(I),L2(I)))
8215 IF RND(Z)<ABS(Q(L1(I),L2(I))+Z)/1000 THEN L3(I)=2 : IF L8=0 THEN PRINT "Contact lost with probe"
8225 L5(I) = L5(I) - Z : IF L5(I)>T THEN 8125
8235 NEXT : RETURN
8305 REM LONG RANGE PROBE STATUS
8315 GOSUB 70 : PRINT "PROBE";" QUADRANT";" SENSORS"
8325 FOR I = 0 TO 7 : PRINT I+Z;" "; : IF L3(I) = 0 THEN PRINT "READY FOR LAUNCH " : GOTO 8405
8335 IF L3(I) = 2 THEN PRINT "DESTROYED" : GOTO 8405
8345 IF SQR((L1(I)-Q1)^2+(L2(I)-Q2)^2)>5 THEN PRINT "OUT OF RANGE" : GOTO 8405
8355 PRINT L1(I)+Z;",";L2(I)+Z;" ";" ";
8365 IF L1(I)<0 OR L1(I)>7 OR L2(I)<0 OR L2(I)>7 THEN PRINT "$$$"; : GOTO 8395
8375 E$ = STR$(Q(L1(I),L2(I))) : E$ = "00"+MID$(E$,2) : PRINT RIGHT$(E$,3) ;
8385 IF D(5) = 0 THEN Q(L1(I),L2(I)) = ABS(Q(L1(I),L2(I)))
8395 PRINT
8405 NEXT : RETURN
Copyright (c) Joe Kasser 1989